var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    ifShownoData: true,
    picArr: [],
    siteOrderId: '',
    payData: {}
  },
  getPicture: function() {
    var that = this;
    wx.showLoading({ title: '加载中' });
    wx.request({
      method: 'POST',
      url: app.preUrl + 'getSiteOrderImg',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        siteOrderId: that.data.siteOrderId
      },
      success: function(res) {
        wx.hideLoading();
        if (res.data.code == 100) {
          let data = res.data.result;
          console.log(data);
          if (data.length) {
            that.setData({ ifShownoData: true, picArr: data });
          }
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.message,
            confirmColor: '#56BDE0',
            showCancel: false
          });
        }
      },
      fail: function(error) {}
    });
  },
  toExamine: function() {
    let that = this;
    wx.showLoading({ title: '审核中' });
    wx.request({
      method: 'POST',
      url: app.preUrl + 'updateOrderStatus',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        id: that.data.siteOrderId,
        orderStatus: 4
      },
      success: function(res) {
        wx.hideLoading();
        console.log(res);
        if (res.data.code == 100) {
          wx.showToast({
            title: '审核成功',
            icon: 'success',
            duration: 1000
          });
          setTimeout(function() {
            wx.redirectTo({
              url: 'payment?data=' + JSON.stringify(that.data.payData)
            });
          }, 1000);
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.message,
            confirmColor: '#56BDE0',
            showCancel: false
          });
          that.setData({ buthidden: false });
        }
      },
      fail: function(error) {
        console.log(error);
        that.setData({ buthidden: false });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options);
    this.setData({
      siteOrderId: options.id,
      payData: JSON.parse(options.data)
    });
    this.getPicture();
  }
});
